#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/6/15 19:18
# @Author  : LiShan
# @Email   : lishan_1997@126.com
# @File    : extract_pic.py
# @Note    : this is note
import os.path
import cv2.cv2 as cv

save_path = "./picture"
width = 480
height = 360

if os.path.exists(save_path):
    pass
else:
    os.mkdir(save_path)

video_path = "./video/background_model.mp4"
vc = cv.VideoCapture(video_path)
fps = int(vc.get(cv.CAP_PROP_FPS))

cnt = 0
while vc.isOpened():
    ret, frame = vc.read()
    if ret:
        cnt += 1
        # 调整图片大小：原图、（宽，高）
        frame = cv.resize(frame, (width, height))
        cv.imwrite(save_path + "/%d.jpg" % cnt, frame)
        cv.imshow("frame", frame)
    k = cv.waitKey(1) & 0xff
    if k == 27:
        break

vc.release()
cv.destroyAllWindows()
